package coolapk.cj.demo.controller;

import coolapk.cj.demo.domain.JSONResult;
import coolapk.cj.demo.domain.Person;
import coolapk.cj.demo.service.person.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program: demo
 * @description: 参与人
 * @author: SDH
 * @create: 2019-04-16 16:45
 */
@RestController
@ResponseBody
public class PersonController {
	@Autowired
	PersonService personService;

	/**
	 * 添加参与人到指定的抽奖项
	 *
	 * @param qq
	 * @param id
	 * @return
	 */
	@PostMapping({"/insertPerson"})
	public JSONResult insertPerson(String qq, int id) {
		Person person = new Person();
		person.setGoodsId(id);
		person.setQq(qq);
		Person person1 = personService.selectByPrimaryKey(person);
		if(person1 != null){
			return JSONResult.build(500, "你已经报名,不允许重复报名", null);
		}
		int result = personService.insert(person);
		if (result > 0) {
			return JSONResult.build(200, "ok", null);
		} else {
			return JSONResult.build(500, "error", null);
		}
	}
}
